package cn.com.infinitus.uits.api;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;

import cn.com.infinitus.uits.auto.uits.BaseDao;
import cn.com.infinitus.uits.service.TimeUtil;

/**
 * 
 * @author 潘科材
 * 获取个人购贷，个人推荐数据
 */
@Controller
@RequestMapping("/personOder")
public class PersonOrder {
	/**
	 * 个人购贷
	 * @param app
	 * @return
	 */
	@RequestMapping(value = "/buy", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	public @ResponseBody String buy(
			HttpServletRequest request){
		BaseDao baseDao = new BaseDao();
		baseDao.openSession();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("the_date", TimeUtil.getYesterday());
		List<Map<String,Object>> list = baseDao.query("GET_PRESON_BUY_BY_DAY", map) ;
		JSONObject jo = new JSONObject();
		jo.put("resp_code", "00000") ;
		jo.put("resp_desc", "OK") ;
		jo.put("data_list", list) ;
		baseDao.closeSession();
		return String.format("%s(%s)", request.getParameter("callback"), jo.toJSONString());
	}
	
	
	/**
	 * 个人购贷
	 * @param app
	 * @return
	 */
	@RequestMapping(value = "/refer", method = RequestMethod.GET, produces = "text/html;charset=UTF-8")
	public @ResponseBody String refer(
			HttpServletRequest request){
		BaseDao baseDao = new BaseDao();
		baseDao.openSession();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("the_date", TimeUtil.getYesterday());
		List<Map<String,Object>> list = baseDao.query("GET_PRESON_REFER_BY_DAY", map) ;
		JSONObject jo = new JSONObject();
		jo.put("resp_code", "00000") ;
		jo.put("resp_desc", "OK") ;
		jo.put("data_list", list) ;
		baseDao.closeSession();
		
		return String.format("%s(%s)", request.getParameter("callback"), jo.toJSONString());

	}
	
}
